<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <style>
        .main {
            text-align: center;
            width: 100%;
            height: 768px;
        }

        .login {
            width: 800px;
            height: 480px;
            margin: 150px auto;
        }
    </style>
</head>
<body>
<div class="main">
    <h2>day06-SpringMvcDemo2-RBAC!</h2>
    <select name="menu">
        <c:choose>
            <c:when test="${sessionScope.loginUser != null}">
                <c:forEach items="${sessionScope.loginUser.roles}" var="role">
                    <c:forEach items="${role.permissions}" var="permission">
                        <c:if test="${permission.pid == 0}">
                            <option value="${permission.permissionPkId}">${permission.permissionName}</option>
                        </c:if>
                    </c:forEach>
                </c:forEach>
            </c:when>
        </c:choose>
    </select>
    <c:choose>
        <c:when test="${sessionScope.loginUser != null}">
            ${sessionScope.loginUser.userName}<a href="logout"> 退出登录</a>
            <div class="login">
                <div>
                    <dl>
                        <c:forEach items="${sessionScope.loginUser.permissions}" var="p">
                            <c:if test="${p.pid == 0}">
                                <dt>${p.permissionName}</dt>
                            </c:if>
                            <c:if test="${p.pid != 0}">
                                <dd><a href="${p.moduleUrl}">${p.permissionName}</a></dd>
                            </c:if>
                        </c:forEach>
                    </dl>
                </div>
                <table width="800px" border="1px" cellspacing="0">
                    <caption><h1>User List</h1></caption>
                    <caption>
                        <form method="post" action="query">
                            <input type="text" name="roleName" placeholder="通过角色名查询">
                            <input type="submit" value="query">
                        </form>
                    </caption>
                    <tr id="header">
                        <td>用户名</td>
                        <td>昵称</td>
                        <td>头像</td>
                        <td>电话</td>
                        <td>城市</td>
                        <td>角色</td>
                        <td>操作</td>
                    </tr>
                    <c:forEach items="${requestScope.users}" var="user">
                        <tr>
                            <td>${user.userName}</td>
                            <td>${user.nickName}</td>
                            <td><img src="${user.userDetail.userImg}" alt="img" width="50" height="50"></td>
                            <td>${user.userDetail.userTel}</td>
                            <td>${user.userDetail.userAddress}</td>
                            <td>${user.roles[0].roleName}</td>
                            <td>
                                <input type="button" value="del">
                                <input type="button" value="info">
                            </td>
                        </tr>
                    </c:forEach>
                </table>
            </div>
        </c:when>
        <c:otherwise>
            <div>请先<a href="jump">登录</a></div>
        </c:otherwise>
    </c:choose>
</div>


</body>
</html>
